package 排序查找;

import java.util.Arrays;

public class 二分查找 {
    public static int binary_search(int[] nums,int target,int start,int end) {
        int mid = (start+end)/2;
        if (start > end) {
            return -1;
        }
        if (nums[mid]<target) {
            return binary_search(nums,target,mid+1,end);
        }
        else if (nums[mid]>target) {
            return binary_search(nums,target,start,mid-1);
        }
        else {
            return mid;
        }
    }

    public static void main(String[] args) {
        bubble.bubble_test(common.nums);
        System.out.println(Arrays.toString(common.nums));
        System.out.println(binary_search(common.nums,2,0,common.nums.length-1));
    }
}
